<?php
    class Solution {
        /**
         * 118. 杨辉三角
         * @param Integer $numRows
         * @return Integer[][]
         */
        function generate118($numRows) {
            $arr = [[1]];
            for ($i = 1; $i < $numRows; $i++) {
                $arr2 = [];
                for ($j = 0; $j < $i+1; $j++) {
                    $arr2[$j] =
                        ($arr[$i-1][$j-1]?:0) + ($arr[$i-1][$j]?:0);
                    ;
                }
                $arr[$i] = $arr2;
            }
            return $arr;
        }

        /**
         * 119. 杨辉三角 II
         * @param Integer $rowIndex
         * @return Integer[]
         */
        function getRow119($rowIndex) {
            $arr = [[1]];
            for ($i = 1; $i < $rowIndex+1; $i++) {
                $arr2 = [];
                for ($j = 0; $j < $i+1; $j++) {
                    $arr2[$j] =
                        ($arr[$i-1][$j-1]?:0) + ($arr[$i-1][$j]?:0);
                    ;
                }
                $arr[$i] = $arr2;
            }
            return $arr[$rowIndex];
        }

        /**
         * 121. 买卖股票的最佳时机
         * @param Integer[] $prices
         * @return Integer
         */
        function maxProfit121($prices) {
            $low = $prices[0];
            $sell = 0;
            $count = count($prices);
            for ($i = 1; $i < $count; $i++) {
                if($low > $prices[$i]) {
                    $low = $prices[$i];
                }
                if(($prices[$i] - $low) > $sell) {
                    $sell = $prices[$i] - $low;
                }
            }

            return $sell;
        }

        /**
         * 125. 验证回文串
         * @param String $s
         * @return Boolean
         */
        function isPalindrome125($s) {
            $left = 0;
            $right = strlen($s)-1;
            $check = true;
            while ($left < $right) {
                if(!ctype_alnum($s[$left])) {
                    $left++;
                    continue;
                }
                if(!ctype_alnum($s[$right])) {
                    $right--;
                    continue;
                }
                if(strcasecmp($s[$left], $s[$right]) != 0) {
                    $check = false;
                    break;
                }
                $left++;
                $right--;
            }

            return $check;
        }


        /**
         * 136. 只出现一次的数字
         * @param Integer[] $nums
         * @return Integer
         */
        function singleNumber136($nums) {
            $hash = [];
            $time = [];
            foreach ($nums as $num) {
                if(!$hash[$num]) {
                    $hash[$num] = 1;
                    $time[$num] = $num;
                }else{
                    unset($time[$num]);
                }
            }

            return current($time);
        }

        /**
         * 168. Excel 表列名称
         * @param Integer $columnNumber
         * @return String
         */
        function convertToTitle168($columnNumber) {
            $count = '';
            while($columnNumber>26)
            {
                if($columnNumber%26==0)
                {
                    $count = 'Z' . $count;
                    $columnNumber = intval($columnNumber/26)-1;
                    continue;
                }
                $count = chr(($columnNumber%26)+64) . $count;
                $columnNumber = intval($columnNumber/26);
            }
            $count = chr($columnNumber+64) . $count;
            return($count);
        }

        /**
         * 169. 多数元素
         * @param Integer[] $nums
         * @return Integer
         */
        function majorityElement169($nums) {
            $n = count($nums);
            $hash = [];
            foreach ($nums as $num) {
                echo $num;
                if(!$hash[$num]) {
                    $hash[$num] = 0;
                }
                $hash[$num]++;
                if($hash[$num] > $n/2) {
                    return $num;
                }
            }
        }

        /**
         * 171. Excel 表列序号
         * @param String $columnTitle
         * @return Integer
         */
        function titleToNumber171($columnTitle) {
            $length = strlen($columnTitle);
            $count = 0;
            $a = 0;
            for ($i = $length-1; $i >= 0; $i--) {
                $a += (ord($columnTitle[$i]) - 64) * (26**$count);
                $count++;
            }
            return $a;
        }

        /**
         * 175. 组合两个表
         * @return void
         */
        function sql175()
        {
            $sql = 'select firstName,lastName,city,state 
                    from Person
                    LEFT JOIN Address 
                    ON Person.personId = Address.personId';
        }

        /**
         * 181. 超过经理收入的员工
         * @return void
         */
        function sql181()
        {
            $sql = 'select a.name as employee from employee as a
                    left join employee as b on a.managerId = b.id
                    where a.salary > b.salary';
        }

    }

    $solution = new Solution();
    $columnTitle = 'AA';
    print_r($solution->titleToNumber171($columnTitle));

?>